﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;

namespace DirectoryTree
{
    class Program
    {
        static void Main(string[] args)
        {

            string fileName = "../../dirs.xml";
            Encoding encoding = Encoding.GetEncoding("windows-1251");
            using (XmlTextWriter writer = new XmlTextWriter(fileName, encoding))
            {
                writer.Formatting = Formatting.Indented;
                writer.IndentChar = '\t';
                writer.Indentation = 1;
                writer.WriteStartDocument();
                DirectoryInfo dir = new DirectoryInfo(@"C:\Users\Milen\Desktop\Telerik");
                //writer.WriteStartElement("directoriesAndFiles");
                DirSearch(dir, writer);
                writer.WriteEndDocument();
            }


        }
        public static void DirSearch(DirectoryInfo sDir, XmlTextWriter writer)
        {
            writer.WriteStartElement("dir");
            writer.WriteAttributeString("name", sDir.Name);
            foreach (FileInfo f in sDir.GetFiles())
            {

                writer.WriteStartElement("file");
                writer.WriteAttributeString("name", f.Name);
                writer.WriteEndElement();

            }
            foreach (DirectoryInfo d in sDir.GetDirectories())
            {

                DirSearch(d, writer);
            }
            writer.WriteEndElement();
        }

    }


}
